<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.1</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="css/public.css" media="all">

  </head>
  
  <body>
   
      <!--表格-->
      <table id="demo" lay-filter="test"></table>

    </div>

    <!--toolbar :头部工具栏-->
    <!--<script type="text/html" id="toolbarDemo">
      <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">新增问题</button>
      </div>
    </script>-->

    <!--tool :右侧工具栏-->
    <script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" lay-event="addAs">回答</a>
      <a class="layui-btn layui-btn-xs" lay-event="edit">审核</a>
<!--      <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
    </script>

		
    <script type="text/html" id="dateTpl">
        {{layui.util.toDateString(new Date(d.publishTime).getTime(), "yyyy-MM-dd HH:mm") }}
    </script>

<script src="lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="api/baseApi.js" charset="utf-8"></script>
<script th:inline="none">
      layui.use(['laydate','table','form'], function(){
        var laydate = layui.laydate;
        var table = layui.table;
        var form = layui.form;
				var $ = layui.$;
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
				
		
        //第一个实例
        table.render({
          elem: '#demo'
          ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
          ,defaultToolbar: ['filter', 'exports', 'print']//自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
          ,url: baseUrl + qsUncheckBaseUrl + 'pageQsUncheckList'	//数据接口
          ,page: true //开启分页
          ,limit: 10
          ,limits: [10,20,30]
          ,cols: [[ //表头
            {type: 'numbers', fixed: 'left' }
            ,{field: 'id', title: 'ID', width:100, sort: true, fixed: 'left'}
			,{field: 'nickname', title: '作者昵称', width:100 }
			,{field: 'name', title: '类型', width:100 }
            ,{field: 'question', title: '文章标题', width:300}
			,{field: 'introduce', title: '简介', width:300 }
			,{field: 'creatTime', title: '创建时间', width:160 ,templet:'#dateTpl',sort:'true'}
			,{field: 'checkTime', title: '审核时间', width:160 ,templet:'#dateTpl'}
            ,{field: 'checkDescribe', title: '审核描述', width:160 }
            ,{field: 'state', title: '审核状态',width:100 ,templet: function(d){
                    if( d.state == 1){
                        return '<span style="color : orange;">未通过</span>';
                    }else if(d.state == 2){
                        return '<span style="color : green;">通过</span>';
                    }else{
                        return '<span style="color : red;">待审</span>';
                    }
            }}
            ,{fixed: 'right', align:'center', toolbar: '#barDemo'}
          ]]
          ,text: {
            none: '暂无相关数据或权限不够'
          }
        });


        //头工具栏事件
        table.on('toolbar(test)', function(obj){
          var checkStatus = table.checkStatus(obj.config.id);
          switch(obj.event){
            case 'add':
              var data = checkStatus.data;
              //layer.alert(JSON.stringify(data));
              let index = layer.open({
                title:'添加问题',
                type:2,
                shade:0.2,
                maxmin:true,
                shadeClose:true,
                area:['100%','100%'],
                content:'qsAdd',
                yes: function(index, layero){
                  parent.location.reload(); // 父页面刷新
                  var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                  parent.layer.close(index);
                }
              })
              break;
            case 'batchDel':
              var data = checkStatus.data;
              layer.msg('选中了：'+ data.length + ' 个');
              break;
                  //自定义头工具栏右侧图标 - 提示
            case 'LAYTABLE_TIPS':
              layer.alert('这是工具栏右侧自定义的一个图标按钮');
              break;
          };
        });


        //监听行工具事件
        table.on('tool(test)', function(obj){
          var data = obj.data;
          console.log(obj)
          if(obj.event === 'del'){
            layer.confirm('真的删除行么?', function(index){
              obj.del();
              $.ajax({
                url: baseUrl + qsUncheckBaseUrl +data.id,
                type:'delete',
                success:function(res){
                  layer.msg("删除成功")
                  table.reload('demo')
                },
                error:function(res){
                  layer.msg("删除失败")
                }
              })
              layer.close(index);
            });
          } else if(obj.event === 'edit'){
            //将数据存入本地sessionData中
            layui.sessionData('qsData',{
              key:'qs'
              ,value:data
            })
            let index = layer.open({
              title:'问题审核',
              type:2,
              shade:0.2,
              maxmin:true,
              shadeClose:true,
              area:['100%','100%'],
              content:'qsCheck',
              yes: function(index, layero){
                parent.location.reload(); // 父页面刷新
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
              }
            })
          } else if(obj.event === 'addAs'){
            //将数据存入本地sessionData中
            layui.sessionData('qsData',{
              key:'qs'
              ,value:data
            })
            let index = layer.open({
              title:'回答问题',
              type:2,
              shade:0.2,
              maxmin:true,
              shadeClose:true,
              area:['100%','100%'],
              content:'asAdd',
              yes: function(index, layero){
                parent.location.reload(); // 父页面刷新
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
              }
            })
          }
        });



      });
</script>

    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
  </body>

</html>